package com.casper.codechef;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class LittleElephant{

	private static String[] arrayC;
	public static final int MAX_TEST_COUNT = 10000;

	private static String[] getLucky(String[] array1, String[] array2) {

		String[] array3 = getMax(reorders(array1), reorders(array2));

		String[] array4 = remove(array3);

		return array4;

	}

	private static String[] remove(String[] array3) {
		String[] temp = new String[array3.length];

		for (int i = 0; i < array3.length; i++) {
			temp[i] = remove1(array3[i]);
		}
		return temp;

	}

	private static String remove1(String string) {

		StringBuilder output = new StringBuilder(string.length());

		for (int i = 0; i < string.length(); i++) {
			if ((Character.getNumericValue(string.charAt(i)) == 7)
					|| (Character.getNumericValue(string.charAt(i)) == 4))
				output.append(Character.getNumericValue(string.charAt(i)));

		}

		return output.toString();
	}

	private static String[] getMax(String[] strings, String[] strings2) {
		String[] temp = new String[strings.length];
		for (int i = 0; i < strings.length; i++) {
			temp[i] = (getMaxNumber(strings[i], strings2[i]));
		}
		return temp;

	}

	private static String getMaxNumber(String string, String string2) {

		StringBuilder output = new StringBuilder(string.length());

		for (int i = 0; i < string.length(); i++) {
			output.append(Math.max(Character.getNumericValue(string.charAt(i)),
					Character.getNumericValue(string2.charAt(i))));

		}

		return output.toString();

	}

	private static String[] reorders(String[] array) {
		String[] temp = new String[array.length];

		for (int j = 0; j < array.length; j++) {
			temp[j] = shuffle(array[j]);

		}
		return temp;

	}

	public static String shuffle(String s) {
		List<Character> characters = new ArrayList<Character>();
		for (char c : s.toCharArray()) {
			characters.add(c);
		}
		StringBuilder output = new StringBuilder(s.length());
		while (characters.size() != 0) {
			int randPicker = (int) (Math.random() * characters.size());
			output.append(characters.remove(randPicker));
		}
		return (output.toString());
	}

	LittleElephant() throws IOException {
		DigitArray arrayA;
		DigitArray arrayB;
		BufferedReader bufferedReader = new BufferedReader(
				new InputStreamReader(System.in));
		int mTestCases = Integer.parseInt(bufferedReader.readLine());
		arrayA = new DigitArray(mTestCases);
		arrayB = new DigitArray(mTestCases);
		if (mTestCases > MAX_TEST_COUNT)
			throw new IOException("Maximum text count is " + MAX_TEST_COUNT);

		for (int i = 0; i < mTestCases * 2; i++) {
			if (i % 2 == 0)
				arrayA.add(bufferedReader.readLine());
			else
				arrayB.add(bufferedReader.readLine());

		}
		arrayC = getLucky(arrayA.getArray(), arrayB.getArray());
		for (int i = 0; i < arrayC.length; i++)
			System.out.println(arrayC[i]);
	}

	public static void main(String[] args) throws IOException {
		new LittleElephant();

	}

	class DigitArray {
		public static final int MAX_LENGTH = 20000;
		public static final int MAX_OVERALL_LENGTH = 200000;

		String[] array;
		int mSize;
		int mIndex = 0;

		public DigitArray(int size) {
			this.mSize = size;
			array = new String[mSize];
		}

		public String get(int index) {
			if (index > mSize) {
				throw new ArrayIndexOutOfBoundsException();
			}
			return array[index];
		}

		public void add(String element) {
			if (mIndex < mSize) {
				if (checkConditions(element)) {
					array[mIndex++] = element;
				}
			} else
				throw new ArrayStoreException();
		}

		public int size() {
			return mSize;
		}

		private boolean checkConditions(String element) {

			int total = 0;
			if (mIndex > 0) {
				for (int i = 0; i < mIndex; i++) {
					total += array[i].length();
				}
				total += element.length();
			}
			if (element.length() <= MAX_LENGTH && total <= MAX_OVERALL_LENGTH)
				return true;
			else
				throw new StringIndexOutOfBoundsException();

		}

		public String[] getArray() {
			return array;
		}
	}

}
